<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('卡片列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-md-12 search-collapse" style="padding-bottom: 0px;margin-bottom: 15px">
            <form id="formId">
                <div class="select-list">
                    <ul style="text-align: left">
                        <li>
                            <label style="width: 80px">日期：</label>
                            <input type="text" id="dimMonth" placeholder="yyyy-MM" autocomplete="off" th:value="${lastMonth}">
                        </li>
                        <li>
                            <label style="width: 80px">名称：</label>
                            <input type="text" name="na" id="name"/>
                        </li>
                        <li>
                            <label style="width: 80px"><span style="color: red">*</span>标签：</label>
                            <input type="hidden" id="treeId"/>
                            <input type="text" onclick="selectDeptTree()" id="treeName" readonly="true" required>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="queryAll()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="checkAll()"><i class="fa fa-refresh"></i>&nbsp;一键核对</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <span style="color: red;margin-left: 30px;font-size: 15px">注意：数据核对相对耗时，轻易勿用，控制使用时机。只有核对无误的数据才能审核通过。</span>
        <div id="dataDiv">

        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script>
    $(function () {
        $("#dimMonth").datetimepicker({
            format: "yyyy-mm",
            startView: 3,
            minView: 3,
            autoclose: true
        });
        queryAll();
    });
    var tableDataHtml = function (item) {
        var indexHtml = '<tr><td>条数</td><td>'+item.hosSize+'</td><td>'+item.dmSize+'</td><td></td></tr>';
        if(Math.abs(Number(item.diff))>1) {
            indexHtml +='<tr style="color:red"><td>统计值</td><td>'+item.hosTotal+'</td><td>'+item.dmTotal+'</td><td>'+item.diff+'</td></tr>';
        } else {
            indexHtml +='<tr><td>统计值</td><td>'+item.hosTotal+'</td><td>'+item.dmTotal+'</td><td>'+item.diff+'</td></tr>';
        }
        return indexHtml;
    }
    function queryAll() {
        $("#dataDiv").html("");
        var dimMonth = $("#dimMonth").val();
        $.ajax({
            type: "GET",
            url: "/etl/check/auto/queryAll?dtType=M&dt="+$("#dimMonth").val(),
            dataType: 'json',
            success: function (res) {
                if(res.code==0) {
                    var indexHtml;
                    $.each(res.data,function (index,item) {
                        indexHtml ='<div class="col-sm-4">\n' +
                            '            <div class="ibox">\n' +
                            '                <div class="ibox-title">\n' +
                            '                    <span class="label label-primary pull-right"><a href="#" onclick="rCheck(\''+item.idIndex+'\',this)">核对</a></span>\n' +
                            '                    <h5>'+item.naIndex+'['+dimMonth+']'+'</h5>\n' +
                            '                </div>\n' +
                            '                <div class="ibox-content">\n' +
                            '                    <h4>核对时间：<span class="timeSpan">'+item.dtSysCre+'</span></h4>\n' +
                            '                    <table class="table table-bordered">\n' +
                            '                        <thead>\n' +
                            '                        <tr>\n' +
                            '                            <th>分类</th>\n' +
                            '                            <th>医院</th>\n' +
                            '                            <th>统计层</th>\n' +
                            '                            <th>差值</th>\n' +
                            '                        </tr></thead><tbody>\n';
                        indexHtml += tableDataHtml(item);
                        indexHtml += '</tbody></table>\n' +
                            '                </div>\n' +
                            '            </div>\n' +
                            '        </div>';
                        $("#dataDiv").append(indexHtml);
                    });
                } else {
                    $.modal.alertError(res.msg);
                }
            }
        });
    }
    function checkAll() {
        $.modal.confirm("确定要对["+$("#dimMonth").val()+"]全月指标做审核吗？过程中可不断点击搜索查看。", function() {
            $.ajax({
                type: "GET",
                url: "/etl/check/auto/checkAll?dt="+$("#dimMonth").val()+"&dtType=M",
                dataType: 'json',
                success:function () {
                    $.modal.closeLoading();
                },
                error:function () {
                    $.modal.closeLoading();
                }
            });
            $.modal.loading("数据审核中");
        });
    }
    function rCheck(idIndex,ele) {
        $.modal.confirm("核对会覆盖原有核对记录是否继续？", function() {
            $.ajax({
                type: "GET",
                url: "/etl/check/auto/reCheck?dt="+$("#dimMonth").val()+"&idIndex="+idIndex+"&dtType=M",
                dataType: 'json',
                success: function (res) {
                    if(res.code==0) {
                        var item = res.data;
                        var div = $(ele).parent().parent().parent();
                        div.find("table tbody").html(tableDataHtml(item));
                        div.find("span.timeSpan").html(item.dtSysCre);
                        $.modal.alertSuccess("指标["+item.naIndex+"]核对完成");
                    } else {
                        $.modal.alertError(res.msg);
                    }
                    $.modal.closeLoading();
                },
                error:function () {
                    $.modal.closeLoading();
                }
            });
            $.modal.loading("数据审核中");
        });
    }
</script>
</body>
</html>